<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>自定义表明细</title>
        <#include "/pubHeadStyleTree.html">
    </head>
    <body>
        <div style="position: relative;height: 100%;">
            <div class="ccpui-trees">
                <p class="isShowTree colorSwitch">
                    <span style="float: left;color: white">&nbsp;&nbsp;组织机构管理</span>
                    <!--<i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>-->
                </p>
                <div style="margin-top: 6px;">
                    <ul class="ccpui-iconTree iconTrees">
                        <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
                        <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
                        <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
                        <input type="text" style="width: 50%" class="resZtreeValue">
                    </ul>
                    <ul id="treeSelectUsers" class="ztree ccpui-listZtree"
                        style="background: #fff;overflow: auto;"></ul>
                </div>
            </div>
            <div class="ccpui-coreContent">
                <div class="layui-form-item">
                    <div class="layui-upload-drag" type="file" id="xmlFile" style="text-align: center;margin: 90px">
                        <i class="layui-icon"></i>
                        <p>点击上传，或将文件拖拽到此处</p>
                    </div>
                </div>
                <div class="layui-btn-container" style="bottom:0;position: absolute;text-align: center;left: 38%;">
                    <button class="layui-btn layui-btn-sm" id="importButton">
                        <span>导入</span>
                    </button>
                    <a class="layui-btn layui-btn-sm layui-btn-danger" id="return">
                        <span>取消</span>
                    </a>
                </div>
            </div>
        </div>
        <script>
            layui.config({
                base: serverPath.formPath + staticPath.formPath //静态资源所在路径
            }).extend({
                index: 'index' //主入口模块
            }).use(['index', 'setter', 'commons', 'layer', 'upload', 'jquery'], function () {
                var layer = layui.layer, $ = layui.jquery, setter = layui.setter, upload = layui.upload,commons=layui.commons;
                //关闭弹窗
                var index = parent.layer.getFrameIndex(window.name);
                $('#return').click(function () {
                    parent.layer.close(index);
                });

                //选中的左侧角色树的节点ID
                var selectOrgId = "";
                var tenantId = "";
                //文件上传
                upload.render({
                    elem: '#xmlFile'
                    , url: serverPath.formPath + setter.formLinkPath + 'table/importXml'
                    , accept: 'file'
                    , multiple: true
                    , auto: false //选择文件后不自动上传
                    , bindAction: '#importButton' //指向一个按钮触发上传
                    , data: {
                        tenantId: function () {
                            return tenantId;
                        }
                    }
                    , before: function (obj) {
                        if (tenantId !== "") {
                            $("input.layui-upload-file").after('<input type="hidden" name="tenantId" value="' + tenantId + '"/>');
                        }
                    }
                    , done: function (res) {
                        if (res.code == 1) {
                            window.parent.layer.alert(res.msg);
                            $(".layui-upload-choose").text("");
                        } else {
                            layer.alert(res.msg, {skin: 'btn-class'}, function () {
                                commons.bulletWindow(index);
                                parent.layui.table.reload('customTable', {
                                    page: {
                                        curr: 1
                                    }
                                });
                                parent.layui.totalFilter.init('customTable');
                            });
                        }
                    }
                });

                //树状结构
                orgZtree();

                function orgZtree() {
                    $.ajax({
                        url: serverPath.formPath + setter.sysLinkPath + "sysOrg/list",
                        type: "get",
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (data) {
                            var zNodes = data.data;
                            var setting = {
                                view: {
                                    showLine: false,
                                    nameIsHTML: true, //允许name支持html
                                    selectedMulti: false
                                },
                                edit: {
                                    enable: false,
                                    editNameSelectAll: false
                                },
                                data: {
                                    simpleData: {
                                        enable: true,
                                        idKey:"orgId",
                                        pIdKey:"orgSupId"
                                    }
                                },
                                callback: {
                                    onClick: onClickUsers
                                }
                            };
                            $.fn.zTree.init($('#treeSelectUsers'), setting, zNodes);
                            var _li=$("#treeSelectUsers_1_ul").find("li");
                            for(i in _li){
                                _li.eq(i).find("a").attr("title", _li.eq(i).find("a").text());
                            }
                            component.fuzzySearch('treeSelectUsers', '.resZtreeValue', null, true); //初始化模糊搜索方法
                        }
                    });
                }

                function onClickUsers(event, treeId, treeNode, clickFlag) {
                    selectOrgId = treeNode.orgId;
                    $.ajax({
                        url: serverPath.formPath + '/out/getTenIdByOrgId',
                        type: "post",
                        data: {"orgId": selectOrgId},
                        success: function (result) {
                            tenantId = result;
                        }
                    });
                }

                //展开
                $(".iconTrees .zTree-triangle-d").click(function () {
                    $.fn.zTree.getZTreeObj("treeSelectUsers").expandAll(true);
                });
                //收起
                $(".iconTrees .zTree-triangle-r").click(function () {
                    $.fn.zTree.getZTreeObj("treeSelectUsers").expandAll(false);
                });
                //刷新
                $(".iconTrees .zTree-refresh").click(function () {
                    orgZtree();
                });
            });
        </script>
        <style>
            .layui-form-item .layui-inline {
                position: absolute;
                bottom: 42%;
                left: 22%;
            }

            .ccpui-coreContent .layui-form-item .layui-upload-form {
                margin-top: 100px;
            }
        </style>
    </body>
</html>